<?php

use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use website\helpers\Render;
use common\models\Design;
use common\models\User;
use common\models\UserEducation;
use common\models\UserCollection;

$this->addCrumbs('设计师', 'search/designer');
$this->title = $user->nickname.'的简历';
?>
<link rel="stylesheet" href="<?= Url::to('@web/web/static/css/user.css') ?>">
<style>
    #designer-header {height:280px;color:#fff;background-color:rgba(0,0,0,.5);}
    #designer-header a:hover,
    #designer-header a {color:#fff;}
    #basic-information {position:relative;height:260px;padding-top:20px;}
    #photo {position:absolute;width:200px;text-align:center;}
    #photo img {height:260px;width:260px;border-radius:100%;}
    #good-at {margin-left:360px;margin-top:50px;line-height:30px;}

    #employ {padding:80px 150px;font-size:16px;}
    #employ .type {margin-right:341px;}
    #employ span.flyer-status {margin-right:20px;padding:5px 10px;}
    #employ button:first-child {margin-right:180px;}
    #design-list .panel {position:relative;}
    #design-list .panel .collection-data {position:absolute;top:10px;right:10px;display:none;}
    #design-list .panel:hover .collection-data {display:block;}
</style>

<div id="designer-header">
    <div class="contenter">
        <?= $this->render('/layouts/break-crumbs') ?>

        <div id="basic-information">
            <div id="photo"><img src="<?= Render::upload($user->photo) ?>"></div>
            <div id="good-at">
                <p class="fs-18px"><?= $user->nickname ?>（<?= '**'.mb_substr($user->realname,-1,1,'utf-8')?>）</p>
                <p>擅长类目：<span class="categories"><?= implode(',', ArrayHelper::getColumn($user->categories, 'category_id')) ?></span></p>
                <p>擅长风格：<span class="styles"><?= Render::text(Design::$styleSelector, ArrayHelper::getColumn($user->styles, 'category_id'), false) ?></span></p>
                <p>擅长软件：<?= Render::value($user, 'skills', '---') ?></p>
                <p>
                    <span class="mr-40px">标签：<?= Render::value($user, 'tags', '---') ?></span>
                    月薪要求：<span class="cl-red fs-24px mr-20px">￥<?= Render::amount($user->salary, 0) ?></span>
                </p>
            </div>
        </div>
    </div>
</div>
<?php if(Yii::$app->isLogin() && Yii::$app->user->employer()) { ?>
    <div class="contenter box-shadow mb-20px">
        <div id="employ">
            <!--p>
                <span class="type">雇佣类型：<span class="flyer-status red">定制</span></span>
                <span class="cycle">雇佣周期：<span class="flyer-status red">包月</span><span class="flyer-status red">包季</span><span class="flyer-status red">包半年</span><span class="flyer-status red">包年</span></span>
            </p-->
            <p class="mt-40px">
                <a class="flyer-button normal border-round huge" href="<?= Url::to('@web/employer/employment?designer_id='.$user->id) ?>">立即雇佣</a>
                <a class="flyer-button normal border-round huge" style="margin-left:100px;">查看联系方式</a>
            </p>
        </div>
    </div>
<?php } else { ?>
    <div class="contenter mt-40px pt-20px"></div>
<?php } ?>
<div class="contenter box-shadow mb-20px">
    <div class="data-title tab">
        <span class="h3 active"><a class="cl-red" href="#basic"><i class="icon-user"></i> 基本信息</a></span>
        <span class="h3"><a href="#education"><i class="icon-building"></i> 教育经历</a></span>
        <span class="h3"><a href="#job"><i class="icon-legal"></i> 工作经历</a></span>
        <span class="h3"><a href="#design"><i class="icon-desktop"></i> 作品展示</a></span>
        <span class="h3"><a href="#star"><i class="icon-star"></i> 综合评价</a></span>
    </div>
    <div class="data-content">
        <!-- basic -->
        <div class="sub-title" id="basic"><i></i>基本信息<span class="english">Basic Information</span></div>
        <div class="flyer-form">
            <div class="form-item">
                <div class="item-inline">
                    <div class="input-title">工作经验：</div>
                    <div class="input-inline input-mid fs"><?= Render::text(User::$workLifeSelector, $user->work_life, false) ?></div>
                </div>
                <div class="item-inline">
                    <div class="input-title">性别：</div>
                    <div class="input-inline input-mid fs"><?= Render::text(User::$genderSelector, $user->gender, false) ?></div>
                </div>
                <div class="item-inline">
                    <div class="input-title">生日：</div>
                    <div class="input-inline input-mid fs"><?= Render::value($user, 'birthday') ?></div>
                </div>
            </div>
            <div class="form-item">
                <div class="input-title">现居住地：</div>
                <div class="input-block input-mid fs"><?= Render::value($user, 'address', '---') ?></div>
            </div>
            <div class="form-item">
                <div class="input-title">个人评价：</div>
                <div class="input-block input-mid fs"><?= Render::value($user, 'describe', '设计师很懒，什么都没写') ?></div>
            </div>
        </div>
        <!-- education -->
        <div class="sub-title mt-40px" id="education"><i></i>教育经历<span class="english">Education</span></div>
        <div class="flyer-form">
            <div class="form-item">
                <div class="item-inline">
                    <div class="input-title">就读时间：</div>
                    <div class="input-inline input-mid fs"><?= Render::value($user, 'education.begin') ?></div>
                </div>
                <div class="item-inline">
                    <div class="input-title">毕业时间：</div>
                    <div class="input-inline input-mid fs"><?= Render::value($user, 'education.finish') ?></div>
                </div>
            </div>
            <div class="form-item">
                <div class="item-inline">
                    <div class="input-title">就读院校：</div>
                    <div class="input-inline input-mid fs"><?= Render::value($user, 'education.school') ?></div>
                </div>
                <div class="item-inline">
                    <div class="input-title">院系专业：</div>
                    <div class="input-inline input-mid fs"><?= Render::value($user, 'education.major') ?></div>
                </div>
                <div class="item-inline">
                    <div class="input-title">学历学位：</div>
                    <div class="input-inline input-mid fs"><?= Render::text(UserEducation::$degreeSelector, Render::value($user, 'education.degree'), false) ?></div>
                </div>
            </div>
        </div>
        <!-- job -->
        <div class="sub-title mt-40px" id="job"><i></i>工作经历<span class="english">Work Experence</span></div>
        <div class="jobs mb-20px" id="job-list"></div>
        <!-- design -->
        <div class="sub-title mt-40px" id="design"><i></i>作品展示<span class="english">Exhibition Of Works</span></div>
        <div class="conter clear" id="design-list"></div>
    </div>
</div>
<div class="contenter box-shadow mb-20px">
    <div class="data-title" id="star"><span class="h3 active"><i class="icon-star"></i> 综合评价</span></div>
    <div class="data-content pd-20px">
        <?php foreach($user->evaluates as $evaluate) { ?>
            <div class="lh-35px bb">
                <h3><span class="mr-20px">评价人：<?= $evaluate->employer->nickname ?></span><span>评价：<?= $evaluate->remark ?></span></h3>
                <p>
                    沟通：<span class="mr-20px cl-red"><?= Render::star($evaluate->communicate) ?></span>
                    创意：<span class="mr-20px cl-red"><?= Render::star($evaluate->originality) ?></span>
                    效率：<span class="mr-20px cl-red"><?= Render::star($evaluate->efficiency) ?></span>
                    专业：<span class="cl-red"><?= Render::star($evaluate->major) ?></span>
                </p>
            </div>
        <?php } ?>
    </div>
</div>

<div id="render" style="display:none;">
    <?= Render::select('style', \common\models\Design::$styleSelector, null) ?>
</div>
<script src="<?= Render::static('art-template/template.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tabler.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tableHandler.class.js') ?>"></script>
<script src="<?= Render::static('flyer/categorier.class.js') ?>"></script>
<script src="<?= Render::static('system/category-design.data.js') ?>"></script>
<script>
    var categorierClass = new categorier();
    $(document).ready(function() {
        // 设置分类内容
        categorierClass.setData(DesignCategories).setRelate(DesignCategoriesRelation);
        tableHandler.renderCategory({ category: $('#basic-information .categories'), color: false, splite: '，', functionName: function(id) {
            return categorierClass.renderTitles(id, false);
        }});
        // 工作经历初始化
        var data = $.parseJSON('<?= json_encode($user->getJobs()->asArray()->all()) ?>');
        initJobTemplate(data);
        // 初始化表格异步加载事件
        (new tabler).init({
            // 请求地址
            url: '<?= Url::to('@web/search/designer-design?designer_id='.$user->id) ?>', showLoading: false,
            // 数据渲染配置
            table: '#design-list', template: 'info-template', readyCall: true,
            afterPost: function(param) {
                tableHandler.renderCategory({ category: $('.styles'), select: '#render select[name=style]', color: false, splite: '，', default: '--' });
                // 初始化 收藏按钮事件
                tableHandler.requestSingle({
                    button: $(param.tabler).find('.collection-data'), url: "<?= Url::to('@web/user/collection') ?>", isConfirm: false, trKey: '.design-detail',
                    beforePost: function(params) {
                        params.data = { handle: $(params.mthis).attr('data-handle'), id: $(params.tr).attr('data-id'), type: '<?= UserCollection::TypeDesign ?>' };
                    },
                    requestSuccess: function(params) {
                        if($(params.mthis).attr('data-handle') == 'collection') {
                            $(params.mthis).attr('data-handle', 'revoke').html('取消收藏');
                        }
                        else {
                            $(params.mthis).attr('data-handle', 'collection').html('加入收藏');
                        }
                    }
                });
            }
        });
    });

    // 渲染工作经历展示
    function initJobTemplate(data)
    {
        $('#job-list').append(template('job-template', { infos: data }));
        var jobDetail = [];
        for(var i = 0; i < data.length; ++i) {
            jobDetail.push('.job-' + data[i].id);
        }
        var jobDom = jobDetail.join(', ');
        // 名称显示
        tableHandler.renderCategory({ category: $(jobDom).find('.nature'), color: false, select: '#flyer-job select[name=nature]' });
        tableHandler.renderCategory({
            category: $(jobDom).find('.category_id'), color: false, functionName: function(id) {
                return categorierClass.renderTitle(id);
            }
        });
    }
</script>

<script id="job-template" type="text/html">
    {{if infos != undefined && infos.length}}
    {{each infos as info key}}
    <div class="job-detail job-{{info.id}}">
        <i class="squal-spliter icon-stop icon-spring"></i>
        <div class="timer"><p>{{info.begin}}</p><p>/</p><p>{{info.finish}}</p></div>
        <div class="describer">
            <p>公司名称：<span class="company">{{info.company}}</span></p>
            <p>公司网址：<span class="wetsite">{{info.website}}</span></p>
            <p>
                <span class="w-250px">工作岗位：<span class="post">{{info.post}}</span></span>
                <span class="w-250px">行业分类：<span class="category_id">{{info.category_id}}</span></span>
                <span class="w-250px">工作性质：<span class="nature">{{info.nature}}</span></span>
            </p>
            <p>工作描述：<span class="describe">{{info.describe}}</span></p>
        </div>
    </div>
    {{/each}}
    {{/if}}
</script>
<script id="info-template" type="text/html">
    {{if infos != undefined && infos.length}}
    {{each infos as info key}}
    <div class="design-detail split4 boxing transition" id="tr-{{info.id}}" data-id="{{info.id}}">
        <div class="panel">
            <div class="imager" style="background-image:url(<?= Render::upload('{{info.thumb}}') ?>);">
                <a href="<?= Url::to('@web/seer/design?id={{info.id}}') ?>"></a>
            </div>
            <div class="bodyer">
                <div class="title">{{info.title}}<span class="design-style styles">{{info.style}}</span></div>
                <div class="user clear">
                    <div class="view"><i class="icon-eye-open"></i>{{info.view}}</div>
                    <div class="collection"><i class="icon-heart cl-red"></i>{{info.collection}}</div>
                    <div class="username"><p>{{info.designer.nickname}}</p><p class="cl-red fs-12px">{{info.designer.star | star}}</p></div>
                </div>
            </div>
            <?php if(Yii::$app->isLogin() && Yii::$app->user->employer()) { ?>
                {{if collection[info.id]}}
                <button class="collection-data flyer-button normal border-round narrow thin" data-handle="revoke">取消收藏</button>
                {{else}}
                <button class="collection-data flyer-button normal border-round narrow thin" data-handle="collection">加入收藏</button>
                {{/if}}
            <?php } ?>
        </div>
    </div>
    {{/each}}
    {{else}}
    <div class="pd-10px"><i class="icon-ban-circle"></i> 暂时没有找到相匹配的作品！</div>
    {{/if}}
</script>